package main

import (
	"fmt"
	"math/rand"
	"sort"
	"strings"
	"time"
)

func main() {
	//a:=map[string]string {
	//	"username": "lyq",
	//	"password": "123",
	//}
	//var b = make(map[string]string)
	//fmt.Printf("%v\n", a)
	//fmt.Printf("%v\n", b)
	//_,ok:=a["qyl"]
	//if	ok {
	//	fmt.Println(a)
	//}
	//for k,v:=range a {
	//	fmt.Println(k,v)
	//}
	//delete(a,"username")
	//for k:=range a {
	//	fmt.Println(k)
	//}
	//sortMap()
	//test()
	//sliceMapTest()
	getNumberOfWords()
}
func sortMap() {
	rand.Seed(time.Now().UnixNano())
	var scoreMap = make(map[string]int, 200)
	for i := 0; i < 100; i++ {
		key := fmt.Sprintf("stu%02d", i)
		value := rand.Intn(100)
		scoreMap[key] = value
	}
	//fmt.Printf("%v",scoreMap)
	var tmp = make([]string, 0, 200)
	for k := range scoreMap {
		fmt.Printf("%T", k)
		tmp = append(tmp, k)
		scoreMap["hah"] = 1
	}
	//fmt.Printf("%v",tmp)
	sort.Strings(tmp)
	fmt.Printf("%v", scoreMap)
}
func test() {
	//a :=[7]int{1,2,3,4,5,6,7}
	//for  b,c :=range a{
	//	fmt.Println(c)
	//	if b==0 {
	//		a[1],a[2]=22,33
	//		fmt.Println(a)
	//	}
	//	a[b]=c+10
	//}
	//fmt.Println(a)
	//a :=[]int{1,2,3,4,5,6,7}
	//for  b,c :=range a{
	//	fmt.Println(c)
	//	if b==0 {
	//		a[1],a[2]=22,33
	//	}
	//	a[b]=c+10
	//}
	//fmt.Println(a)
}

//func sliceMapTest () {
//	var sliceMap = make(map[string][]string, 3)
//	fmt.Println(sliceMap)
//	fmt.Println("after init")
//	key := "中国"
//	value, ok := sliceMap[key]
//	if !ok {
//		value = make([]string, 0, 2)
//	}
//	value = append(value, "北京", "上海")
//	sliceMap[key] = value
//	fmt.Println(sliceMap)
//}
func getNumberOfWords() {
	var str = "how do you do"
	arr := strings.Split(str, " ")
	fmt.Println(arr)
	wordsMap := make(map[string]int)
	for _, v := range arr {
		wordsMap[v]++
	}
	fmt.Println(wordsMap)
}
